const app = getApp()
import BaseModel from '../../utils/common.js'
Page({

      /**
       * 页面的初始数据
       */
      data: {
        id:"",
        page:1,
        size:12, //每页条数
        depart_name:"",//部门
        count:"",//数量
        departmentTypeAllData:[],//分类数据
        footer_more:"",
        empty_title:"",
        empty_img:"",
        empty_again:"",//重试
        is_clickTab:0 //重试或下拉是0，上啦是1
      },
      /**
       * 生命周期函数--监听页面加载
       */
      onLoad: function (options) {
          this.setData({
              id:options.id
          })
        this.departmentTypeAllData(); //员工数据
      },

      /*全部员工数据*/
      departmentTypeAllDataModel: new BaseModel({
        url: 'getStaffOrganizer',
        method: "get",
        needAjaxLoading:true,
        loadingText:"玩命加载中"
      }),
      departmentTypeAllData() {
        this.departmentTypeAllDataModel
            .fetch({
              "department_id":this.data.id,
              "page": this.data.page,
              "size": this.data.size
            })
            .then(res => {
                if(this.data.is_clickTab==0){
                    this.setData({
                        departmentTypeAllData: res.data.staff,
                        depart_name:res.data.depart_name,
                        count:res.data.count,
                        empty_title:"暂无数据",
                        empty_img:"http://hwj2018.oss-cn-beijing.aliyuncs.com/hwj2019/icon_new3.0/empty_mes.png",
                        empty_again:"",//重试
                    })
                }else{
                    if(res.data.staff==""){
                        this.setData({
                            footer_more:"没有更多数据了"
                        })
                    }else{
                        //成功
                        var departmentTypeAllData_list = this.data.departmentTypeAllData;
                        for(var i=0;i<res.data.staff.length;i++){
                            departmentTypeAllData_list.push(res.data.staff[i])
                        }
                        this.setData({
                            departmentTypeAllData: departmentTypeAllData_list,
                            depart_name:res.data.depart_name,
                            count:res.data.count
                        })
                    }
                }

            })
            .catch(res => {
              //失败
              this.setData({
                  empty_title:"请求失败",
                  empty_img:"http://hwj2018.oss-cn-beijing.aliyuncs.com/hwj2019/icon/empty_data.png",
                  empty_again:"重试",//重试
              })
            })
      },
    //重试
    again_request:function(){
        this.setData({
            is_clickTab:0,
            page:1
        })
        this.departmentTypeAllData();
    },
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        this.setData({
            is_clickTab:0,
            page:1
        })
        this.departmentTypeAllData();
        wx.stopPullDownRefresh(); //停止下拉
    },
    /**
       * 页面上拉触底事件的处理函数
       */
      onReachBottom: function () {
        var that = this;
        that.data.page+=1;
        this.setData({
            is_clickTab:1
        })
        this.departmentTypeAllData();
      },



/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {

},

/**
 * 生命周期函数--监听页面显示
 */
onShow: function () {

},

/**
 * 生命周期函数--监听页面隐藏
 */
onHide: function () {

},

/**
 * 生命周期函数--监听页面卸载
 */
onUnload: function () {

},

})